<template>
  <div class="container">
    <div class="input_modal">
      <div class="input-item">
        <span>姓名：</span>
        <el-input v-model="realname" placeholder="请输入内容" class="proName" @keyup.enter.native="search"></el-input>
      </div>
      <div class="input-item">
        <span>手机号：</span>
        <el-input v-model="mobile" placeholder="请输入内容" class="proName" @keyup.enter.native="search"></el-input>
      </div>
      <div class="input-item">
        <el-button icon="el-icon-search" type="primary" size="medium" @click="getList">查询</el-button>
      </div>
    </div>
    <div class="table_con">
      <el-table v-loading="loading" :data="tableData" :border='true'>
        <el-table-column :formatter="formatter" prop="realname" label="姓名"></el-table-column>
        <el-table-column :formatter="formatter" prop="company" label="公司名称"></el-table-column>
        <el-table-column :formatter="formatter" prop="mobile" label="手机号"></el-table-column>
        <el-table-column :formatter="formatter" prop="bookingTime" label="预约时间"></el-table-column>
        <el-table-column :formatter="formatter" prop="gmtCreated" label="提交时间"></el-table-column>
        <el-table-column :formatter="formatter" prop="status" label="状态">
          <template slot-scope="scope">
            <div v-if="scope.row.status == 'WAIT_PROCESSING'">等待处理</div>
            <div v-else-if="scope.row.status == 'PROCESSED'">已处理</div>
          </template>
        </el-table-column>
        <el-table-column prop="" label="操作" width='120'>
          <template slot-scope="scope">
            <el-button type="primary" size="mini" @click="handleDeal(scope.row.id)" v-if="scope.row.status == 'WAIT_PROCESSING'">处理</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>

    <div class="pagination">
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page.sync="pageIndex" :page-size="pageSize" :page-sizes='[10,20,30,40]' layout="total, sizes, prev, pager, next, jumper" :total="pageCount">
      </el-pagination>
    </div>
  </div>
</template>

<script>
  let CONSTANT = require("../../constant/constant.js");
  let common = require("../../common.js");
  export default {
    data() {
      return {
        tableData: [],
        pageCount: null,
        pageIndex: 1,
        pageSize: 10,
        loading: true,
        buildingName: "",
        mobile: "",
        realname: ""
      };
    },
    mounted() {
      this.getList();
    },
    methods: {
      formatter(row, column, cellValue) {
        return cellValue ? cellValue : "- -";
      },
      getList: function() {
        let url = CONSTANT.URL.ORDER.consultList;
        let data = {
          pageIndex: this.pageIndex,
          pageSize: this.pageSize,
          realname: this.realname,
          mobile: this.mobile
        };
        this.loading = true;
        common.requestAjax(url, JSON.stringify(data), null, res => {
          this.loading = false;
          let data = res.data;
          this.tableData = data.bussData;
          this.pageCount = data.count;
        });
      },
      handleDeal(id) {
        this.$confirm("确定处理?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(() => {
            let url = CONSTANT.URL.ORDER.consult;
            common.put(url, id, '', res => {
              if (res.status == 200) {
                this.$message({
                  type: "success",
                  message: "处理成功!"
                });
                this.getList();
              } else {
                this.$message({
                  type: "warning",
                  message: res.data.errMsg
                });
              }
            });
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消处理"
            });
          });
      },
      search: function(e) {
        if (e.keyCode == 13) {
          this.pageIndex = 1;
          this.getList();
        }
      },
      handleSizeChange(val) {
        this.pageSize = val;
        this.getList();
      },
      handleCurrentChange(val) {
        this.pageIndex = val;
        this.getList();
      }
    }
  };
</script>
